package ModelLayer;

import java.util.ArrayList;
/**
 * Write a description of class PersonLib here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PersonLib
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> personLib;
    
    private static PersonLib instance;
    /**
     * Constructor for objects of class PersonLib
     */
    private PersonLib()
    {
        personLib = new ArrayList<Person>();
    }

    public static PersonLib getPersonLib()
    {
        if(instance == null)
        {
            instance = new PersonLib();
        }
        
        return instance;
    }
    
    public Employee getEmployeeByLogin(int _employeeId, String password)
    {
        Employee retEmployee = null;
        int index = 0;
        boolean found = false;

        while(index < personLib.size() && !found)
        {
            Person currPerson = personLib.get(index);
            
            if(currPerson instanceof Employee)
            {
                Employee currEmployee = (Employee)currPerson;
                
                if(currEmployee.getEmployeeId() == _employeeId && currEmployee.getPassword().equals(password))
                {
                    retEmployee = currEmployee;
                    found = true;
                }
            }
            
            index++;
        }
        
        return retEmployee;
    }
    
    public Person getCustomerByPhoneNr(String _phoneNr)
    {
        Person retPerson = null;
        int index = 0;
        boolean found = false;
        
        while(index < personLib.size() && !found)
        {
            Person currPerson = personLib.get(index);
            
            if(currPerson.getPhoneNr().equals(_phoneNr))
            {
                retPerson = currPerson;
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        return retPerson;
    }
    public void addPerson(Person person)
    {
        personLib.add(person);
    }
}
